package com.daiqile.myinterest.activity;

import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.util.Log;
import android.view.MotionEvent;
import android.view.View;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.daiqile.myinterest.R;
import com.daiqile.myinterest.customview.NewSrollView;
import com.daiqile.myinterest.customview.ObservableScrollView;

import butterknife.BindView;
import butterknife.ButterKnife;

public class ThirdActivity extends AppCompatActivity implements ObservableScrollView.OnObservableScrollViewScrollChanged, NewSrollView.OnNewScrollViewScrollChanged {


    @BindView(R.id.tv_s_one)
    TextView tvSOne;
    @BindView(R.id.tv_l_one)
    TextView tvLOne;
    @BindView(R.id.tv_f_one)
    TextView tvFOne;
    @BindView(R.id.o_scrollView)
    ObservableScrollView oScrollView;
    @BindView(R.id.o_NewscrollView)
    NewSrollView oNewscrollView;
    @BindView(R.id.tv_s_two)
    TextView tvSTwo;
    @BindView(R.id.ll_parent)
    LinearLayout llParent;
    @BindView(R.id.tv_f_two)
    TextView tvFTwo;
    private int tvSHeight;
    private int tvFHeight;
    private int tvLHeight;
    private int lltwoHeight;


    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_third);
        ButterKnife.bind(this);
        oScrollView.setOnObservableScrollViewScrollChanged(this);
        oNewscrollView.setOnNewScrollViewScrollChanged(this);
        llParent.setOnTouchListener(new View.OnTouchListener() {
            @Override
            public boolean onTouch(View v, MotionEvent event) {
                if (event.getAction() == MotionEvent.ACTION_UP) {
                    //允许ScrollView截断点击事件，ScrollView可滑动
                    oScrollView.requestDisallowInterceptTouchEvent(true);
                } else {
                    //不允许ScrollView截断点击事件，点击事件由子View处理
                    oScrollView.requestDisallowInterceptTouchEvent(false);
                }
                return false;
            }
        });
    }

    @Override
    public void onWindowFocusChanged(boolean hasFocus) {
        super.onWindowFocusChanged(hasFocus);
        if (hasFocus) {
            tvSHeight = tvSOne.getHeight();
            tvFHeight = tvFOne.getHeight();
            tvLHeight = tvLOne.getHeight();
            Log.d("oneHeight", String.valueOf(tvSHeight));
            Log.d("twoHeight", String.valueOf(tvFHeight));
            Log.d("lunHeight", String.valueOf(tvLHeight));

        }
    }

    @Override
    public void onObservableScrollViewScrollChanged(int l, int t, int oldl, int oldt) {
        if (t > 0 && t <= tvLHeight) {
            tvSTwo.setVisibility(View.VISIBLE);
        } else if (t > tvLHeight && t <= tvLHeight + tvSHeight) {
            tvSTwo.setY(-(t - tvLHeight));
            tvFTwo.setVisibility(View.GONE);
        } else if (t > tvLHeight + tvSHeight ) {
            tvFTwo.setVisibility(View.VISIBLE);
        } else if (t <= tvLHeight + tvSHeight ){
            tvFTwo.setVisibility(View.GONE);}
        }


    @Override
    public void onNewScrollViewScrollChanged(int l, int t, int oldl, int oldt) {

    }

}
